package org.anq.ddm.controller;


import io.swagger.annotations.Api;
import org.anq.ddm.service.FormService;
import org.anq.ddm.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/form/serve/")
public class ServeFormController {

    @Autowired
    FormService formService;


    /**
     * 本人申请任务列表 UI
     * @return 用以展示本人申请任务列表的 form json
     */
    @GetMapping(value = "/request")
    public ApiResult getRequestServeForm() {
        String formId = "serve_form_request";
        ApiResult result = new ApiResult();
        result.setData(this.formService.findByFromKey(formId).getFormvalue());
        return result;
    }


    /**
     * 待审核任务列表(所有，未分类) UI
     * @return 用以展示待审核任务列表的 form json
     */
    @GetMapping(value="/review")
    public ApiResult getReviewServeForm(@RequestParam(required = false) String processKey) {
        // todo 如果 processKey 不空，则根据流程查找 form UI
        // 否则返回不分类 UI Form Json
        ApiResult result = new ApiResult();
        String formId = "serve_form_review";
        result.setData(this.formService.findByFromKey(formId).getFormvalue());
        return result;
    }


    /**
     * 本人已完成任务列表(所有，未分类) UI
     * @return 用以展示待审核任务列表的 form json
     */
    @GetMapping(value="/selfdone")
    public ApiResult getSelfDoneServeForm() {
        ApiResult result = new ApiResult();
        String formId = "serve_form_self_done";
        result.setData(this.formService.findByFromKey(formId).getFormvalue());
        return result;
    }


    /**
     * TODO 本人申请任务列表数据
     * @return 本人申请任务列表数据
     */
    @GetMapping(value = "/requests")
    public ApiResult getRequestServeData(){
        ApiResult result = new ApiResult();

        List list = new ArrayList<>();

        Map<String, Object> item = new HashMap<>();
        item.put("id", "001");
        item.put("title", "本人申请一");
        item.put("data", "摘要一、摘要二");
        list.add(item);

        Map<String, Object> item2 = new HashMap<>();
        item2.put("id", "002");
        item2.put("title", "本人申请一");
        item2.put("data", "摘要一、摘要二");
        list.add(item2);

        result.setData(list);

        return result;

    }



    /**
     * TODO 待审核任务列表数据
     * @return 待审核任务列表数据
     */
    @GetMapping(value = "/reviews")
    public ApiResult getReviewServeData(){
        ApiResult result = new ApiResult();

        List<Map<String, Object>> list = new ArrayList<>();

        Map<String, Object> item = new HashMap<>();
        item.put("id", "001");
        item.put("title", "待审核申请一");
        item.put("data", "摘要一、摘要二");
        list.add(item);

        Map<String, Object> item2 = new HashMap<>();
        item2.put("id", "002");
        item2.put("title", "待审核申请二");
        item2.put("data", "摘要一、摘要二");
        list.add(item2);

        result.setData(list);

        return result;

    }



    /**
     * TODO 本人已完成任务列表数据
     * @return 本人已完成任务列表数据
     */
    @GetMapping(value = "/selfdones")
    public ApiResult getSelfDoneServeData(){
        ApiResult result = new ApiResult();

        List<Map<String, Object>> list = new ArrayList<>();

        Map<String, Object> item = new HashMap<>();
        item.put("id", "001");
        item.put("title", "本人已完成一");
        item.put("data", "摘要一、摘要二");
        list.add(item);

        Map<String, Object> item2 = new HashMap<>();
        item2.put("id", "002");
        item2.put("title", "本人已完成二");
        item2.put("data", "摘要一、摘要二");
        list.add(item2);

        result.setData(list);

        return result;

    }
}
